package MySQL::Query::Performance;

use strict;
use warnings;
use Carp;
use Time::HiRes qw( gettimeofday tv_interval );
use MySQL::Query::Performance::Count;
use MySQL::Query::Performance::GroupBy;

sub new {
      my ($class , %arg) = @_;
	
      #my $dbh = delete $arg{dbh};
      #croak "Database handle (dbh) is mandatory" unless $dbh;
	
      my $count_obj = MySQL::Query::Performance::Count->new();
      my $groupby_obj = MySQL::Query::Performance::GroupBy->new();
        
      my $self = bless {
      #            dbh => $dbh,
		  _count => $count_obj,
                  _groupby => $groupby_obj,
      }, $class;
	
      return $self;
}

sub dbh {
      return shift->{dbh};
}

sub count {
      return shift->{_count};
}

sub groupby {
      return shift->{_groupby};
}

sub benchmark {
      my ($self , $sql) = @_;
	
      if (ref $sql) {
	    $sql = $sql->sql; # if it's an SQL::Builder object
      }
	
      my $t0 = [gettimeofday];
	
      my $sth = $self->dbh->prepare($sql);
      $sth->execute;
	
      return tv_interval ( $t0, [gettimeofday]);
}

1;

=head1 NAME

MySQL::Query::Performance

=head1 SYNOPSIS
	
=head1 DESCRIPTION

=head1 METHODS

=head2 new()

=head2 count()

=head2 groupby()
